#! /bin/sh -vx
# $Id$
# Copyright 2018 Karl Berry <tex-live@tug.org>
# Copyright 2010-2013 Peter Breitenlohner <tex-live@tug.org>
# You may freely use, modify and/or distribute this file.

BinDir=${BinDir:-.}
ExeExt=${ExeExt:-}
_kpsewhich=$BinDir/kpsewhich$ExeExt

TEXMFCNF=$srcdir
export TEXMFCNF

$_kpsewhich --var-value=TEXMFCNF || exit 1  # environment variable
$_kpsewhich --var-value=TEXMFMAIN || exit 2
$_kpsewhich --expand-var=\$TEXMFMAIN || exit 3

# It turns out --all and no --all go through rather different code
# in pathsearch.c, so try them both.

if [ "$ExeExt" = ".exe" ]; then

$_kpsewhich --cnf-line=TEXINPUTS=$srcdir/../tests/texmf \
    --casefold-search --all Plain.TeX || exit 4
$_kpsewhich --cnf-line=TEXINPUTS=$srcdir/../tests/texmf \
    --casefold-search Plain.TeX || exit 5

else

TEXINPUTS=$srcdir/../tests/texmf \
  $_kpsewhich --casefold-search --all Plain.TeX || exit 4
TEXINPUTS=$srcdir/../tests/texmf \
  $_kpsewhich --casefold-search Plain.TeX || exit 5

fi
#
# These runs will succeed on case-insensitive (file)systems, so don't
# run them.
#TEXINPUTS=$srcdir/../tests/texmf \
#  ./kpsewhich --no-casefold-search --all Plain.TeX && exit 6
#TEXINPUTS=$srcdir/../tests/texmf \
#  ./kpsewhich --no-casefold-search Plain.TeX && exit 7

if [ "$ExeExt" = ".exe" ]; then

$_kpsewhich --cnf-line=TEXINPUTS=$srcdir/../tests/texmf \
    --all plain || exit 8

$_kpsewhich --cnf-line=AFMFONTS=$srcdir/../tests/texmf \
    afmtest.afm || exit 9

$_kpsewhich --cnf-line=BSTINPUTS=$srcdir/../tests/texmf \
    plain.bst || exit 10

else

TEXINPUTS=$srcdir/../tests/texmf \
  $_kpsewhich --all plain || exit 8

AFMFONTS=$srcdir/../tests/texmf \
  $_kpsewhich afmtest.afm || exit 9

BSTINPUTS=$srcdir/../tests/texmf \
  $_kpsewhich plain.bst || exit 10

fi
